package top.callname.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 数据库连接工具类
 * @author 维康
 *
 */
public class ConnDB {
	
	public static  String driverName = PropertiesUtil.getDriverName();
	public static  String dbUser = PropertiesUtil.getDbUser();
	public static  String dbPass = PropertiesUtil.getDbPass();
	public static  String dbUrl = PropertiesUtil.getDbUrl();
	public static  Connection conn= null;
	
	public static Connection getConn(){
		try{
			 Class.forName(driverName); 
			 conn = DriverManager.getConnection(dbUrl, dbUser, dbPass);
		}catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	public static void closeDB(Connection conn) throws SQLException{
		if(!conn.isClosed()){
				conn.close();
		}
	}
	public static void closeStatement (Statement st) throws SQLException{
		if(!st.isClosed()){
			st.close();
		}
	}
	
	public static void closeResultSet(ResultSet res) throws SQLException{
		if(!res.isClosed()){
			res.close();
		}
	}
	
}
